package jp.co.showbiz.admin.report.action;

import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;

import jp.co.showbiz.admin.report.imp.ContentInfoDto;
import jp.co.showbiz.admin.report.imp.DigestDto;
import jp.co.showbiz.admin.report.imp.DigestServiceImpl;
import jp.co.showbiz.admin.report.imp.ReportDetailContentDto;
import jp.co.showbiz.admin.report.imp.ReportDto;
import jp.co.showbiz.admin.report.imp.ReportServiceImpl;
import jp.co.showbiz.common.base.BaseActionSupport;
import jp.co.showbiz.common.base.BaseException;
import jp.co.showbiz.common.entity.CommonMstBean;

public class DigestImageAction extends BaseActionSupport {
	private static final long serialVersionUID = -6054838501291221064L;
	private ReportDto rBean;
	private DigestDto dBean;
	private String disc;
	private String discValue;
	protected HashMap<String, String> globeMap;
	private List<Hashtable> digestImageInfos;
	private ContentInfoDto cDto;
	
	public DigestImageAction() throws BaseException, IOException, SQLException {
		globeMap = new HashMap<String, String>();
		globeMap.put("globe.path.commonImg", getText("globe.path.commonImg"));
		globeMap.put("globe.path.root", getText("globe.path.root"));
		globeMap.put("golbe.path.tempDigestImgPath", getText("golbe.path.tempDigestImgPath"));
		globeMap.put("globe.path.base", getText("globe.path.base"));
		globeMap.put("globe.path.photo", getText("globe.path.photo"));
		globeMap.put("globe.path.movie", getText("globe.path.movie"));
		globeMap.put("globe.path.flash", getText("globe.path.flash"));
		globeMap.put("globe.path.voice", getText("globe.path.voice"));
		
		globeMap.put("file.vga.thumb", getText("file.vga.thumb"));
		globeMap.put("file.qvga.thumb", getText("file.qvga.thumb"));
		globeMap.put("file.vga.middle", getText("file.vga.middle"));
		globeMap.put("file.qvga.middle", getText("file.qvga.middle"));
		globeMap.put("file.vga.complete", getText("file.vga.complete"));
		globeMap.put("file.qvga.complete", getText("file.qvga.complete"));
		globeMap.put("file.vga.complete2", getText("file.vga.complete2"));
		globeMap.put("file.qvga.complete2", getText("file.qvga.complete2"));
		
		globeMap.put("file.name.photo", getText("file.name.photo"));
		globeMap.put("file.name.shortmovie", getText("file.name.shortmovie"));
		globeMap.put("file.name.videoclip", getText("file.name.videoclip"));
		globeMap.put("file.name.flashcalender", getText("file.name.flashcalender"));
		globeMap.put("file.name.flashwait", getText("file.name.flashwait"));
		globeMap.put("file.name.voice", getText("file.name.voice"));
		
		ReportServiceImpl service = new ReportServiceImpl(globeMap);
		List<CommonMstBean> discs = service.getKijiDiscValue();
		for (CommonMstBean bean : discs) {
			globeMap.put(bean.getValue(), bean.getName());
		}
	}

	public DigestDto getDBean() {
		return dBean;
	}

	public void setDBean(DigestDto bean) {
		dBean = bean;
	}

	public String getDisc() {
		return disc;
	}

	public void setDisc(String disc) {
		this.disc = disc;
	}

	public String getDiscValue() {
		return discValue;
	}

	public void setDiscValue(String discValue) {
		this.discValue = discValue;
	}

	public HashMap<String, String> getGlobeMap() {
		return globeMap;
	}

	public void setGlobeMap(HashMap<String, String> globeMap) {
		this.globeMap = globeMap;
	}

	private void setDiscValue() {
		if (disc.equals("cover")) {
			discValue = globeMap.get("co");
		} else if (disc.equals("interview")) {
			discValue = globeMap.get("in");
		} else if (disc.equals("issue")) {
			discValue = globeMap.get("is");
		} else if (disc.equals("wideshow")) {
			discValue = globeMap.get("wi");
		}
	}
    
	@Override
	public void prepare() throws Exception {
		if (disc == null) disc = "";
		if (dBean == null) dBean = new DigestDto();
		if (rBean == null) rBean = new ReportDto();
		if (cDto == null) cDto = new ContentInfoDto();
	}
	
	public String execute() throws Exception {
		logger.debug("DigestImageAction.execute");
		setDiscValue();
		DigestServiceImpl service = new DigestServiceImpl();
		setDigestImageInfos(service.getDigestImageInfo(dBean));
		return SUCCESS;
	}
	
    public String modify() throws Exception {
    	logger.debug("DigestImageAction.modify");
    	setDiscValue();
    	DigestServiceImpl service = new DigestServiceImpl();
    	cDto = service.getDigestImageInfo(cDto.getContent_id());
    	return SUCCESS;
    }
    
    public String update() throws Exception {
    	logger.debug("DigestImageAction.update");
    	setDiscValue();
    	DigestServiceImpl service = new DigestServiceImpl(globeMap);
    	service.updadateDigestImageInfo(cDto);
    	return SUCCESS;
    }
    
    public String delete() throws Exception {
    	logger.debug("DigestImageAction.delete");
    	setDiscValue();
    	DigestServiceImpl service = new DigestServiceImpl(globeMap);
    	service.deleteContent(cDto);
    	return SUCCESS;
    }
    
	public ReportDto getRBean() {
		return rBean;
	}

	public void setRBean(ReportDto bean) {
		rBean = bean;
	}

	public List<Hashtable> getDigestImageInfos() {
		return digestImageInfos;
	}

	public void setDigestImageInfos(List<Hashtable> digestImageInfos) {
		this.digestImageInfos = digestImageInfos;
	}

	public ContentInfoDto getCDto() {
		return cDto;
	}

	public void setCDto(ContentInfoDto dto) {
		cDto = dto;
	}

}
